import { defHttp } from "/@/utils/http/axios";
import { Modal } from "ant-design-vue";
import { useGlobSetting } from "/@/hooks/setting";
import { useMessage } from "/@/hooks/web/useMessage";
const { createMessage: $message } = useMessage();
const globSetting = useGlobSetting();
const baseUploadUrl = globSetting.uploadUrl;

export enum Api {
  //行程线路
  list      = "/cmsArticle/datagrid",
  add       = "/cmsArticle/add",
  save      = "/cmsArticle/save",
  copy      = "/cmsArticle/copy",
  delete    = "/cmsArticle/del",
  queryById   = "/cmsArticle/queryById",
  menuSelect  = "/cmsArticle/menuSelect",
  updateState = "/cmsArticle/updateState",

  //顶部图片
  cmsPhotoList = "/cmsPhotoController/cmsArticle",
  cmsPhotoDel  = "/cmsPhotoController/del",
  cmsPhotoSave = "/cmsPhotoController/save",

  //出港地点
  cmsSchepostList = "/cmsScheduleController/cmsSchepost",
  cmsSchepostAdd = "/cmsScheduleController/addSchepost",
  cmsSchepostDel = "/cmsScheduleController/delSchepost",

  //价格排期
  cmsScheduleList = "/cmsScheduleController/cmsArticle",
  cmsScheduleSave = "/cmsScheduleController/save",
  cmsScheduleDel  = "/cmsScheduleController/del",

  //产品行程
  cmsRouteList = "/cmsRouteController/cmsArticle",
  cmsRouteDel  = "/cmsRouteController/del",
  cmsRouteSave = "/cmsRouteController/save",
  cmsRouteReadTrafficTools = "/cmsRouteController/readTrafficTools",

  //产品附件
  cmsFileList = "/cmsFileController/cmsArticle",
  cmsFileDel  = "/cmsFileController/del",

  //产品排期
  cmsGoodsList = "/cmsScheduleController/cmsGoodsList",
  residueList  = "/cmsScheduleController/residueList",

  //收客人
  skrsSelect  = "/cmsMemberController/skrsSelect",
}

/**
 * 文章管理 - 列表
 * @param params
 */
export const testMember = () => defHttp.get({url: "/cmsMemberController/getCurrent?cookieOpenid=oIEgm6_1w00DPht_nXrMHkkxlPwg"});

/**
 * 文章管理 - 列表
 * @param params
 */
export const list = (params) => defHttp.get({url: Api.list, params});

/**
 * 文章管理 - 通过ID获取数据
 * @param params
 */
export const queryById = (params) => defHttp.get({url: Api.queryById, params}, {isTransformResponse:false});

/**
 * 文章管理 - 保存或者更新
 * @param params
 */
export const add = (params) => {
  return defHttp.post({url: Api.add, params}, {isTransformResponse:false});
}

/**
 * 文章管理 - 保存或者更新
 * @param params
 */
export const save = (params) => {
  return defHttp.post({url: Api.save, params}, {isTransformResponse:false});
}

/**
 * 文章管理 - 复制
 * @param params
 */
export const copy = (params) => {
  return defHttp.post({url: Api.copy, params}, {isTransformResponse:false});
}

/**
 * 文章管理 - 通过ID删除数据
 * @param params
 */
export const cmsPhotoDel = (params) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.cmsPhotoDel, data: params }, { joinParamsToUrl: true })
    },
  });
}

/**
 * 文章管理 - 禁用
 * @param params
 */
export const updateState = (params, handleSuccess) => {
  Modal.confirm({
    title: '',
    content: '是否修改线路状态',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({ url: Api.updateState, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
}

/**
 * 文章管理 - 顶部图片
 * @param params
 */
export const cmsPhotoList = (params) => defHttp.get({url: Api.cmsPhotoList, params});

/**
 * 文章管理 - 顶部图片 - 上传保存
 */
export const cmsPhotoUploadUrl = `${baseUploadUrl}/cmsPhotoController/save`;

/**
 * 文章管理 - 通过ID删除数据
 * @param params
 */
export const del = (params, handleSuccess) => {
  // Modal.confirm({
  //   title: '确认删除',
  //   content: '是否删除选中数据',
  //   okText: '确认',
  //   cancelText: '取消',
  //   onOk: () => {
  //
  //   },
  // });
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}

/**
 * 文章管理 - 价格排期 - 初始数据
 * @param params
 */
export const cmsScheduleList = (params) => defHttp.get({url: Api.cmsScheduleList, params});

/**
 * 文章管理 - 价格排期 - 添加数据
 * @param params
 */
export const cmsScheduleSave = (params) => {
  return defHttp.post({url: Api.cmsScheduleSave, params}, {isTransformResponse:false});
}

/**
 * 文章管理 - 价格排期 - 删除数据
 * @param params
 */
export const cmsScheduleDel = (params) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.cmsScheduleDel, data: params }, { joinParamsToUrl: true })
    },
  });
}

/**
 * 文章管理 - 出港地点 - 初始数据
 * @param params
 */
export const cmsSchepostList = (params) => defHttp.get({url: Api.cmsSchepostList, params});

/**
 * 文章管理 - 出港地点 - 添加数据
 * @param params
 */
export const cmsSchepostAdd = (params) => {
  return defHttp.post({url: Api.cmsSchepostAdd, params}, {isTransformResponse:false});
}

/**
 * 文章管理 - 出港地点 - 删除数据
 * @param params
 */
export const cmsSchepostDel = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.cmsSchepostDel, params }, {
        joinParamsToUrl: true,
        isTransformResponse: false
      }).then((res) => {
        if (res.success) {
          $message.success(res.message)
          handleSuccess()
        } else {
          $message.error(res.message)
        }
      });
    },
  });
}

/**
 * 文章管理 - 行程管理
 * @param params
 */
export const cmsRouteList = (params) => defHttp.get({url: Api.cmsRouteList, params});

/**
 * 文章管理 - 底部附件
 * @param params
 */
export const cmsFileList = (params) => defHttp.get({url: Api.cmsFileList, params});

/**
 * 文章管理 - 附件上传 - 上传保存
 */
export const cmsFilesUploadUrl = `${baseUploadUrl}/cmsFileController/save`;

/**
 * 文章管理 - 通过ID删除数据
 * @param params
 */
export const cmsFilesDel = (params) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.cmsFileDel, data: params }, { joinParamsToUrl: true })
    },
  });
}

/**
 * 文章管理 - 价格排期列表
 * @param params
 */
export const cmsGoodsList = (params) => defHttp.get({url: Api.cmsGoodsList, params});

/**
 * 机票余位
 * @param params
 */
export const residueList = (params) => defHttp.get({url: Api.residueList, params});


/**
 * 部门收客人列表
 * @param params
 */
export const skrsSelect = (params) => defHttp.get({url: Api.skrsSelect, params});